package com.itheima.chapter10.producerconsumer;
//消费者
public class Consumer extends Thread{
    @Override
    public void run() {
        while (true) {
            synchronized (Share.lock) {
                if (Share.count==0){
                    break;
                }else{
                    if (Share.flag){
                        System.out.println("消费者使用资源");
                        Share.count--;
                        Share.flag= false;
                        Share.lock.notifyAll();
                    }else {
                        try {
                            Share.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }

    }
}
